package com.example.mychat.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.sun.istack.NotNull;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@Data
public class Message implements Serializable {
    @TableId(type = IdType.ASSIGN_ID)
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    private int receiverId; //接受消息的用户id，-1时表示公开消息，-2时表示写扩散的源消息
    @JsonSerialize(using = ToStringSerializer.class)
    private Long originId; //写扩散源消息的id

    private String username; //消息发布者

    private String text;    //消息内容

    private Date time;    //消息时间

    private Date expirationTime; //过期时间

    public Message() {

    }

    public Message(String userName, int receiverId, String text, Date time, Date expirationTime) {
        this.username = userName;
        this.receiverId = receiverId;
        this.text = text;
        this.time = time;
        this.expirationTime = expirationTime;
    }

    public Message(String userName, int receiverId, String text, Date time, Date expirationTime, Long originId) {
        this.username = userName;
        this.receiverId = receiverId;
        this.text = text;
        this.time = time;
        this.expirationTime = expirationTime;
        this.originId = originId;
    }
}
